package cn.duli.myvideo.controller;

import cn.duli.myvideo.pojo.MovieComment;
import cn.duli.myvideo.service.MovieCommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/movieComment")
public class MovieCommentController {

    @Resource
    private MovieCommentService movieCommentService;

    /**
     * 分页查询所有电影评论列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/findAll")
    public PageInfo<MovieComment> findAll(
            @RequestParam(defaultValue = "1") int pageNo,
            @RequestParam(defaultValue = "2") int pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<MovieComment> pageInfo = new PageInfo<>(movieCommentService.findAll());
        return pageInfo;
    }

    /**
     * 根据用户id查看当前用户下的评论
     * @param uId
     * @return
     */
    @GetMapping("/findByUserId/{uId}")
    public List<MovieComment> findByUserId(@PathVariable("uId") Integer uId){
        return movieCommentService.findByUserId(uId);
    }

    /**
     * 根据电影id查看当前电影下的评论
     * @param mId
     * @return
     */
    @GetMapping("/findById/{mId}")
    public List<MovieComment> findById(@PathVariable("mId") Integer mId){
        return movieCommentService.findById(mId);
    }

    /**
     * 新增评论
     * @param movieComment
     */
    @PostMapping("/save")
    public void save(@RequestBody MovieComment movieComment){
        movieCommentService.save(movieComment);
    }

    /**
     * 根据id删除电影评论
     * @param mcId
     */
    @RequestMapping("/deleteById/{mcId}")
    public void deleteById(@PathVariable("mcId") Integer mcId){
        movieCommentService.deleteById(mcId);
    }
}
